package com.yadong.smarthome2.ui;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yadong.smarthome2.protocol2.ResultProtocol.Function;

public class FunctionListAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    public FunctionListAdapter(Context context) {
        mLayoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    private List<Function> mFunctions = new ArrayList<Function>();

    public void setFunctions(List<Function> functions) {
        this.mFunctions = functions;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mFunctions.size();
    }

    @Override
    public Object getItem(int position) {
        return mFunctions.get(position);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = mLayoutInflater.inflate(
                    android.R.layout.simple_list_item_1, viewGroup, false);
        }
        Function function = mFunctions.get(position);
        TextView textView = ((TextView) view.findViewById(android.R.id.text1));
        textView.setText(function.getDescription());
        return view;
    }
}